/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.dp.controller;

import com.dp.model.Articles;
import com.dp.services.IItemServices;
import com.dp.services.ItemServices;
import com.dp.utils.BaseException;
import com.dp.dto.BaseDTO;
import com.dp.dto.WelcomeDTO;
import com.dp.model.Books;
import java.util.List;

/**
 *
 * @author hisik
 */
public class WelcomeController {
 
    private static final IItemServices itemServices = new ItemServices();
        
    public static void getItemStatistics(WelcomeDTO dto) throws BaseException {
        
        List<Books> books = itemServices.loadBookList();
        List<Articles> articles = itemServices.loadArticleList();
        
        int n1 = 0, n2 = 0, n3 = 0, n4 = 0;
        if(books != null && !books.isEmpty()) {
            for(Books book : books) {
                if(book.getIssueArea().equals("National"))
                    n1++;
                else if(book.getIssueArea().equals("International"))
                    n2++;
            }
            dto.setTotalBook(books.size());
        }
        else
            dto.setTotalBook(0);
        
        if(articles != null && !articles.isEmpty()) {
            for(Articles article : articles) {
                if(article.getIssueArea().equals("National"))
                    n3++;
                else if(article.getIssueArea().equals("International"))
                    n4++;
            }
            dto.setTotalArticle(articles.size());
        }
        else
            dto.setTotalArticle(0);
        
        dto.setNationalBook(n1);
        dto.setInterNationalBook(n2);
        dto.setNationalArticle(n3);
        dto.setInterNationalArticle(n4);
        
    }
}
